/*
 * This file is part of the Shell Library.
 *
 * Copyright (c) 2024, ark, <345473553@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * Function: Is is an head file for this library. You can see all be called functions.
 */

#ifndef __SHELL__
#define __SHELL__

/**************************************************************************************************
 *                                            INCLUDES
 **************************************************************************************************/
#include <stdint.h>
/*********************************************************************
 * CONSTANTS
 */
#define SHELL_OK              0
#define SHELL_ERR             1
#define SHELL_ERR_PARAM       2
#define SHELL_ERR_TOO_LONG    3
#define SHELL_ERR_UNKNOW      4
#define SHELL_ERR_CUSTOM      5
#define SHELL_NOECHO          6


#define SHELL_NEED_FLOAT      0
#define SHELL_NEED_LOGIN      0
#define SHELL_LOGIN_KEY       "ADMIN@666"
#define SHELL_CMD_MAX         0x08
#define SHELL_PARM_MAX        0x04
#define SHELL_COMMAND_MAX     128
#define SHELL_CUSTOM_DESP_MAX 64


/*********************************************************************
 * TYPEDEFS
 */
typedef struct ShellCmd{
    uint8_t (*func)(uint8_t , const char**);
  const char cmd[SHELL_CMD_MAX];
  const char *desp;
}xShellCmd;


/*********************************************************************
 * EXTERNAL VARIABLES
 */
extern const xShellCmd _xshellCmds[]; // 指令列表，在shell_port.c文件中实现，末尾必须为{NULL,NULL,NULL}


/*********************************************************************
 * FUNCTIONS
 *********************************************************************/
uint8_t verify_dec_u8( const char *p );
uint8_t verify_dec_u16( const char *p );
uint8_t verify_dec_u32( const char *p );
uint8_t verify_dec_int( const char *p );
uint8_t verify_dec_flt( const char *p );
uint8_t verify_hex_u8s( const char *p );
uint8_t verify_hex_16b( const char *p );
uint8_t verify_hex_32b( const char *p );
uint8_t convert_hex_to_u8( const char *p);
uint16_t convert_hex_to_u16( const char *p );
uint32_t convert_hex_to_u32( const char *p );
uint8_t* convert_u8_to_hex(  uint8_t *ptr, uint8_t a );
uint8_t* convert_u8s_to_hex( uint8_t *pdst, uint8_t *psrc, uint8_t typ, uint8_t num, uint8_t *prefix );

uint8_t shell_parse( void );
uint8_t shell_put_u8( uint8_t c );
uint8_t shell_put_buf( uint8_t *ptr, uint8_t sz );
uint8_t shell_set_custom_err_desp( const char *pstr );
#endif // __SHELL
